<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>个人信息 - 旅游推荐系统</title>
    <!-- Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        body {
            background-color: #f8f9fa;
            font-family: 'Microsoft YaHei', sans-serif;
        }
        .profile-card {
            border-radius: 10px;
            box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
            transition: all 0.3s;
        }
        .profile-card:hover {
            box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
        }
        .avatar {
            width: 150px;
            height: 150px;
            object-fit: cover;
        }
        .interest-badge {
            padding: 0.5em 0.8em;
            margin-right: 0.5em;
            margin-bottom: 0.5em;
        }
        .section-title {
            border-bottom: 2px solid #dee2e6;
            padding-bottom: 0.5rem;
            margin-bottom: 1.5rem;
        }
    </style>
</head>
<body>
<div class="container py-5">
    <div class="row justify-content-center">
        <div class="col-lg-10">
            <div class="card profile-card mb-4">
                <div class="card-header bg-primary text-white">
                    <h3 class="mb-0"><i class="fas fa-user-circle me-2"></i>个人信息</h3>
                </div>
                <div class="card-body">
                    <div class="row">
                        <!-- 左侧头像和信息 -->
                        <div class="col-md-4 text-center">
                            {% if user.avatar %}
                                <img src="{{ user.avatar.url }}" class="avatar rounded-circle mb-3" alt="用户头像">
                            {% else %}
                                <img src="{% static 'img/default-avatar.jpg' %}" class="avatar rounded-circle mb-3" alt="默认头像">
                            {% endif %}

                            <h4>{{ request.user.username }}</h4>
                            {% if user.nickname %}
                                <p class="text-muted">{{ user.nickname }}</p>
                            {% endif %}

                            <button class="btn btn-primary mt-2" data-bs-toggle="modal" data-bs-target="#editProfileModal">
                                <i class="fas fa-edit me-1"></i>编辑资料
                            </button>
                        </div>

                        <!-- 右侧详细信息 -->
                        <div class="col-md-8">
                            <div class="row">
                                <div class="col-md-6">
                                    <h5 class="section-title">基本信息</h5>
                                    <p><strong><i class="fas fa-venus-mars me-2"></i>性别:</strong>
                                        {% if user.gender == 'M' %}男
                                        {% elif user.gender == 'F' %}女
                                        {% elif user.gender == 'O' %}其他
                                        {% else %}未设置
                                        {% endif %}
                                    </p>
                                    <p><strong><i class="fas fa-birthday-cake me-2"></i>出生日期:</strong>
                                        {% if user.birth_date %}
                                            {{ user.birth_date|date:"Y-m-d" }}
                                        {% else %}
                                            未设置
                                        {% endif %}
                                    </p>
                                    <p><strong><i class="fas fa-map-marker-alt me-2"></i>地区:</strong>
                                        {% if user.province or user.city %}
                                            {{ user.province|default:"" }} {{ user.city|default:"" }} {{ user.district|default:"" }}
                                        {% else %}
                                            未设置
                                        {% endif %}
                                    </p>
                                </div>
                                <div class="col-md-6">
                                    <h5 class="section-title">旅游偏好</h5>
                                    <p><strong><i class="fas fa-calendar-alt me-2"></i>年旅游次数:</strong>
                                        {% if user.travel_frequency %}
                                            {{ user.travel_frequency }} 次
                                        {% else %}
                                            未设置
                                        {% endif %}
                                    </p>
                                    <p><strong><i class="fas fa-money-bill-wave me-2"></i>消费偏好:</strong>
                                        {% if user.budget_preference == 'low' %}经济型
                                        {% elif user.budget_preference == 'medium' %}舒适型
                                        {% elif user.budget_preference == 'high' %}豪华型
                                        {% else %}未设置
                                        {% endif %}
                                    </p>
                                    <p><strong><i class="fab fa-weixin me-2"></i>微信ID:</strong>
                                        {% if user.wechat_id %}
                                            {{ user.wechat_id }}
                                        {% else %}
                                            未设置
                                        {% endif %}
                                    </p>
                                </div>
                            </div>

                            <div class="mt-4">
                                <h5 class="section-title">兴趣标签</h5>
                                {% if user.interests %}
                                    <div class="d-flex flex-wrap">
                                        {% for interest in user.interests.split %}
                                            <span class="badge bg-primary interest-badge">{{ interest }}</span>
                                        {% endfor %}
                                    </div>
                                {% else %}
                                    <p class="text-muted">暂无兴趣标签</p>
                                {% endif %}
                            </div>

                            <div class="mt-4">
                                <h5 class="section-title">个人简介</h5>
                                {% if user.bio %}
                                    <p>{{ user.bio }}</p>
                                {% else %}
                                    <p class="text-muted">暂无个人简介</p>
                                {% endif %}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 编辑资料的模态框 -->
<div class="modal fade" id="editProfileModal" tabindex="-1" aria-labelledby="editProfileModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="editProfileModalLabel">编辑个人资料</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <form method="post" enctype="multipart/form-data">
                {% csrf_token %}
                <div class="modal-body">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label">昵称</label>
                                <input type="text" class="form-control" name="nickname" value="{{ form.nickname.value|default_if_none:'' }}">
                            </div>
                            <div class="mb-3">
                                <label class="form-label">性别</label>
                                <select class="form-select" name="gender">
                                    <option value="U" {% if form.gender.value == 'U' %}selected{% endif %}>未设置</option>
                                    <option value="M" {% if form.gender.value == 'M' %}selected{% endif %}>男</option>
                                    <option value="F" {% if form.gender.value == 'F' %}selected{% endif %}>女</option>
                                    <option value="O" {% if form.gender.value == 'O' %}selected{% endif %}>其他</option>
                                </select>
                            </div>
                            <div class="mb-3">
                                <label class="form-label">出生日期</label>
                                <input type="date" class="form-control" name="birth_date" value="{{ form.birth_date.value|date:'Y-m-d'|default_if_none:'' }}">
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label">省份</label>
                                <input type="text" class="form-control" name="province" value="{{ form.province.value|default_if_none:'' }}">
                            </div>
                            <div class="mb-3">
                                <label class="form-label">城市</label>
                                <input type="text" class="form-control" name="city" value="{{ form.city.value|default_if_none:'' }}">
                            </div>
                            <div class="mb-3">
                                <label class="form-label">区县</label>
                                <input type="text" class="form-control" name="district" value="{{ form.district.value|default_if_none:'' }}">
                            </div>
                        </div>
                    </div>

                    <div class="row mt-2">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label">年旅游次数</label>
                                <input type="number" class="form-control" name="travel_frequency" value="{{ form.travel_frequency.value|default_if_none:'0' }}">
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label class="form-label">消费偏好</label>
                                <select class="form-select" name="budget_preference">
                                    <option value="low" {% if form.budget_preference.value == 'low' %}selected{% endif %}>经济型</option>
                                    <option value="medium" {% if form.budget_preference.value == 'medium' %}selected{% endif %}>舒适型</option>
                                    <option value="high" {% if form.budget_preference.value == 'high' %}selected{% endif %}>豪华型</option>
                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="mb-3">
                        <label class="form-label">头像</label>
                        <input class="form-control" type="file" name="avatar" accept="image/*">
                    </div>

                    <div class="mb-3">
                        <label class="form-label">兴趣标签</label>
                        <input type="text" class="form-control" name="interests" value="{{ form.interests.value|default_if_none:'' }}" placeholder="例如: 历史人文,自然风光,美食探店">
                        <small class="text-muted">多个兴趣用逗号分隔</small>
                    </div>

                    <div class="mb-3">
                        <label class="form-label">微信ID</label>
                        <input type="text" class="form-control" name="wechat_id" value="{{ form.wechat_id.value|default_if_none:'' }}">
                    </div>

                    <div class="mb-3">
                        <label class="form-label">个人简介</label>
                        <textarea class="form-control" name="bio" rows="3">{{ form.bio.value|default_if_none:'' }}</textarea>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-primary">保存更改</button>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- Bootstrap JS Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
    // 简单的表单验证
    document.querySelector('form').addEventListener('submit', function(e) {
        const travelFreq = document.querySelector('input[name="travel_frequency"]');
        if (travelFreq.value < 0) {
            alert('年旅游次数不能为负数');
            e.preventDefault();
        }
    });
</script>
</body>
</html>